/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crypbox.net.backend;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import models.Folder;

/**
 *
 * @author MJ
 */
public class Einstellungen {

    private static Einstellungen instance = null;
    private Folder localBox = null;
    private Folder onlineBox = null;
    private File myBox = new File("C:\\Users\\MJ\\Documents\\Cryptbox.Net");
    public int splitgroesse = 1024 * 500;
    private static final File backupFile = new File("einstellungen");
    private transient final File tempfolder = new File("tempfolder");

    private Einstellungen() {
        if (myBox != null) {
            myBox.mkdirs();
        }
    }

    public static Einstellungen getInstance() {
        if (instance == null) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(backupFile));
                instance = (Einstellungen) ois.readObject();
            } catch (Exception ex) {
                //Badda bumm
            }

            if (instance == null) {
                instance = new Einstellungen();
            }
        }
        return instance;
    }

    public Folder getLocalBox() {
        return localBox;
    }

    public void setLocalBox(Folder localBox) {
        this.localBox = localBox;
        saveSettings();
    }

    public Folder getOnlineBox() {
        return onlineBox;
    }

    public void setOnlineBox(Folder onlineBox) {
        this.onlineBox = onlineBox;
        saveSettings();
    }

    public  int getSplitgroesse() {
        return splitgroesse;
    }

    public File getBackupFile() {
        return backupFile;
    }

    public File getMyBox() {
        return myBox;
    }

    public File getTempfolder() {
        return tempfolder;
    }

    public  void setSplitgroesse(int splitgroesse) {
        this.splitgroesse = splitgroesse;
    }

    public void setMyBox(File myBox) {
        this.myBox = myBox;
        saveSettings();
    }

    private void saveSettings() {
        try {
            backupFile.delete();
            backupFile.createNewFile();
        } catch (Exception ex) {
        }
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(backupFile));
            oos.writeObject(this);
            oos.close();
        } catch (Exception ex) {
        }

    }
}
